Spring Boot使用多线程执行sql语句 |
您所在的位置:网站首页 › sql 多线程查询 › Spring Boot使用多线程执行sql语句 |
1.在Controller层中分别使用submitSql方法提交sql,getResult方法获取线程执行结果 dataService.submitSql(uuid,endsql); return dataService.getResult(uuid);endsql为要执行的sql语句,uuid为唯一标识该条线程信息。 2.在Service层定义线程池的信息,和多线程执行的方法。 2.1定义线程池信息和执行结果格式。 public static ThreadPoolExecutor executor = new ThreadPoolExecutor(5,10, 5,TimeUnit.MINUTES,new ArrayBlockingQueue(5)); public static HashMap resultList = new HashMap();2.2实现Callable方法 public static class SqlTask implements Callable { private String sql; private DataMapper dataMapper; public SqlTask(String sql, DataMapper dataMapper) { this.sql=sql; this.dataMapper=dataMapper |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |